#e
#Title[zNu832v]
#Text[]
#ScriptVersion[2]

script_enemy_main
{
	let scroll=0;
	let flag=0;
	let flag2=0;
	let cx=GetCenterX();
	let cy=GetCenterY();
	let boss=GetCurrentScriptDirectory~"img\boss7-2.png";
	let boss2=GetCurrentScriptDirectory~"img\boss7-3.png";
	let eye=GetCurrentScriptDirectory~"img\bg7-1.png";
	let eye2=GetCurrentScriptDirectory~"img\bg7-1.5.png";
	let asa=GetCurrentScriptDirectory~"img\bg7-2.png";
	let asa2=GetCurrentScriptDirectory~"img\bg7-2.5.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetScore(30000);
		SetLife(400);
		SetDamageRate(10,0);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(80);
		SetInvincibility(60);
		LoadGraphic(boss);
		LoadGraphic(eye);
		LoadGraphic(asa);
		LoadGraphic(boss2);
		LoadGraphic(eye2);
		LoadGraphic(asa2);
		LoadGraphic(GetCurrentScriptDirectory~".\img\shot\bullet.png");
		shottask;
		shottask2;
		subtask;
		movetask;
		drawtask;
		bombtask;
		CutIn(YOUMU,"zNu831v",0,0,0,0,0);
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
		loop(16)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-30,30),GetY+rand(-30,30));
		}
		DeleteGraphic(boss);
		DeleteGraphic(eye);
		DeleteGraphic(asa);
		DeleteGraphic(boss2);
		DeleteGraphic(eye2);
		DeleteGraphic(asa2);
		DeleteGraphic(GetCurrentScriptDirectory~".\img\shot\bullet.png");
	}
	@DrawLoop
	{
		if(flag2%4==0)
		{
			SetColor(255,255,255);
			SetTexture(boss);	
			if(flag==1)
			{
				SetGraphicRect(52,0,81,63);
			}
			else if(flag==2)
			{
				SetGraphicRect(24,0,52,63);
			}
			else
			{
				SetGraphicRect(0,0,24,63);
			}
			SetGraphicScale(1,1);
			SetGraphicAngle(0,0,0);
			DrawGraphic(GetX,GetY);
		}
		if(flag2%4==1)
		{
			SetColor(255,0,0);
			SetTexture(boss);	
			if(flag%4==1)
			{
				SetGraphicRect(52,0,81,63);
			}
			else if(flag==2)
			{
				SetGraphicRect(24,0,52,63);
			}
			else
			{
				SetGraphicRect(0,0,24,63);
			}
			SetGraphicScale(1,1);
			SetGraphicAngle(0,0,0);
			DrawGraphic(GetX,GetY);
		}
		if(flag2%4==2)
		{
			SetColor(0,0,255);
			SetTexture(boss);	
			if(flag==1)
			{
				SetGraphicRect(52,0,81,63);
			}
			else if(flag==2)
			{
				SetGraphicRect(24,0,52,63);
			}
			else
			{
				SetGraphicRect(0,0,24,63);
			}
			SetGraphicScale(1,1);
			SetGraphicAngle(0,0,0);
			DrawGraphic(GetX,GetY);
		}
		if(flag2%4==3)
		{
			SetColor(255,255,255);
			SetTexture(boss2);	
			if(flag==1)
			{
				SetGraphicRect(52,0,81,63);
			}
			else if(flag==2)
			{
				SetGraphicRect(24,0,52,63);
			}
			else
			{
				SetGraphicRect(0,0,24,63);
			}
			SetGraphicScale(1,1);
			SetGraphicAngle(0,0,0);
			DrawGraphic(GetX,GetY);
		}
	}
	@BackGround
	{
		if(flag2%4==0)
		{
			SetColor(255,255,255);
			SetTexture(eye);	
			SetGraphicRect(0,0,384,448);
			SetAlpha(255);
			SetGraphicScale(1,1);
			SetGraphicAngle(0,0,0);
			DrawGraphic(cx,cy);
			SetTexture(asa);	
			SetGraphicRect(0,0,888,189*5);
			SetAlpha(64);
			SetGraphicScale(0.5,0.75);
			SetGraphicAngle(0,0,0);
			DrawGraphic(cx+scroll,cy);
			DrawGraphic(cx+scroll-444,cy);
			if(scroll>444)
			{
				scroll=0;
			}
		}
		if(flag2%4==1)
		{
			SetColor(31,83,189);
			SetTexture(eye);	
			SetGraphicRect(0,0,384,448);
			SetAlpha(255);
			SetGraphicScale(1,1);
			SetGraphicAngle(0,0,0);
			DrawGraphic(cx,cy);
			SetTexture(asa);	
			SetGraphicRect(0,0,888,189*5);
			SetAlpha(64);
			SetGraphicScale(0.5,0.75);
			SetGraphicAngle(0,0,0);
			DrawGraphic(cx+scroll,cy);
			DrawGraphic(cx+scroll-444,cy);
			if(scroll>444)
			{
				scroll=0;
			}
		}
		if(flag2%4==2)
		{
			SetColor(232,71,42);
			SetTexture(eye);	
			SetGraphicRect(0,0,384,448);
			SetAlpha(255);
			SetGraphicScale(1,1);
			SetGraphicAngle(0,0,0);
			DrawGraphic(cx,cy);
			SetTexture(asa);	
			SetGraphicRect(0,0,888,189*5);
			SetAlpha(64);
			SetGraphicScale(0.5,0.75);
			SetGraphicAngle(0,0,0);
			DrawGraphic(cx+scroll,cy);
			DrawGraphic(cx+scroll-444,cy);
			if(scroll>444)
			{
				scroll=0;
			}
		}
		if(flag2%4==3)
		{
			SetColor(255,255,255);
			SetTexture(eye2);	
			SetGraphicRect(0,0,384,448);
			SetAlpha(255);
			SetGraphicScale(1,1);
			SetGraphicAngle(0,0,0);
			DrawGraphic(cx,cy);
			SetTexture(asa2);	
			SetGraphicRect(0,0,888,189*5);
			SetAlpha(64);
			SetGraphicScale(0.5,0.75);
			SetGraphicAngle(0,0,0);
			DrawGraphic(cx+scroll,cy);
			DrawGraphic(cx+scroll-444,cy);
			if(scroll>444)
			{
				scroll=0;
			}
		}
	}
	task shottask
	{
		let angle=0;
		let angle2=0;
		let r=0;
		wait(120);
		loop
		{
			r=0;
			angle=GetAngleToPlayer;
			loop(90)
			{
				loop(3)
				{
					CreateShot01(GetX+r*cos(angle),GetY+r*sin(angle),0.7,angle2,54,0);
					angle+=120;
					angle2+=120;
				}
				angle2+=12;
				r+=6;
				wait(2)
			}
			wait(60);
		}
	}
	task shottask2
	{
		let angle=0;
		wait(120);
		loop
		{
			wait(120);
			angle=GetAngleToPlayer;
			loop(36)
			{
				CreateShotA(1,GetX,GetY,0);
				SetShotDataA(1,0,5,angle,0,-0.1,1.5,117);
				FireShot(1);
				angle-=10;
			}
		}
	}
	task subtask
	{
		wait(600);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNu832v",0,0,0,0,0);
		flag2++;
		wait(480);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNu833v",0,0,0,0,0);
		flag2++;
		wait(480);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNu834v",0,0,0,0,0);
		flag2++;
		wait(480);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNu835v",0,0,0,0,0);
		flag2++;
		wait(480);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNu836v",0,0,0,0,0);
		flag2++;
		wait(480);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNu837v",0,0,0,0,0);
		flag2++;
		wait(480);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNu838v",0,0,0,0,0);
		flag2++;
		wait(480);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNu839v",0,0,0,0,0);
		flag2++;
		wait(480);
		PlaySE(GetCurrentScriptDirectory~"seUseSpellCard.wav");
		CutIn(YOUMU,"zNu840v",0,0,0,0,0);
		flag2++;
		wait(480);
	}
	task movetask
	{
		wait(120);
		loop
		{
			wait(180);
			move(rand(40, 80), rand(-40, 40), 60,GetClipMinX + 32, GetClipMinY + 80,GetClipMaxX - 32, GetClipMinY + 160);
			wait(60);
		}
	}
	task drawtask
	{
		let x=0;
		loop
		{	
			if(GetX>x+0.5)
			{
				flag=1;
			}
			else if(GetX<x-0.5)
			{
				flag=2;
			}
			else
			{
				flag=0;
			}
			x=GetX;
			scroll++;
			yield;
		}
	}
	task bombtask
	{
		loop
		{
			if(OnBomb)
			{
				SetAlpha(64);
				SetDamageRate(0,0);
			}
			else
			{
				SetAlpha(255);
				SetDamageRate(10,0);
				SetCollisionA(GetX(),GetY(),24);
				SetCollisionB(GetX(),GetY(),24);
			}
			yield;
		}
	}
	function move(xMove, yAdd, frame, left, top, right, bottom)
	{
		let x;
		let y;
		if(GetPlayerX < GetX) 
		{
			x = GetX - xMove;
			if(x < left) 
			{
				x = GetX + xMove;
			}
		} 
		else {
			x = GetX + xMove;
			if(right < x)
			{
				x = GetX - xMove;
			}
		}
		y = GetY + yAdd;
		if(y < top)
		{
			y = top;
		}
		else if(bottom < y)
		{
			y = bottom;
		}
		SetMovePosition02(x, y, frame);
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}
